package com.superquan.springcloud;

import com.superquan.springcloud.entity.CommonResult;
import com.superquan.springcloud.entity.Payment;
import com.superquan.springcloud.service.PaymentFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @program: cloud2022
 * @description: openfeign-控制层
 * @author: superquan
 * @create: 2022-05-18 07:45
 **/
@RestController
@Slf4j
public class OrderFeignController {

    @Resource
    private PaymentFeignService paymentFeignService;

    @RequestMapping(value = "/consumer/payment/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable(value = "id")Long id){
        log.info("【开始进入】：consumer-openfeign-order80");
        log.info("【请求参数id】："+id);
        return paymentFeignService.getPaymentById(id);
    }

    /**
     * 演示openFeign超时机制
     * @return
     */
    @GetMapping(value = "/consumer/payment/feign/timeout")
    public String paymentFeignTimeout(){
        //openfeign-ribbon,客户端默认等待一秒钟
        return paymentFeignService.paymentFeignTimeout();
    }
}
